<template>
	<view class="row" @click="btnClick()">
		<slot>
			<text v-if="icon" class="iconfont " :class="icon" :style="iconStyle"></text>
			<text :class="nameClass" :style="nameStyle">{{name}}</text>
		</slot>
	</view>
</template>

<script>
	export default {
		name: "gt-btn",
		props: {
			name: {
				type: String,
				default: function() {
					return '';
				}
			},
			icon: {
				type: String,
				default: function() {
					return '';
				}
			},
			skip: {
				type: String,
				default: function() {
					return '';
				}
			},
			postType: {
				type: String,
				default: function() {
					return 'POST';
				}
			},
			getUrl: {
				type: String,
				default: function() {
					return '';
				}
			},
			getData:{
				type: [String,Object],
				default: function() {
					return '';
				}
			},
			postUrl: {
				type: String,
				default: function() {
					return '';
				}
			},
			postData:{
				type: [String,Object],
				default: function() {
					return '';
				}
			},
			tip: {
				type: String,
				default: function() {
					return '确认操作？';
				}
			},
		},
		data() {
			return {}
		},
		created() {},
		methods: {
			async btnClick() {
				let _this = this;
				if(this.tip){
					if(await this.$fun.showModal(this.tip) == false) return false
				}
				if (this.skip) {
					this.$skip.to(this.skip);
				} else if (this.getUrl) {
					this.$get({
						url: this.getUrl,
						data:this.getData || {},
					});
				} else if (this.postUrl) {
					this.$post({
						url: this.postUrl,
						data: this.postData || {},
						type:this.postType || 'POST',
						afterFun(r) {}
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
